import tensorflow as tf 
from tensorflow import keras


path = './tf_model_save_and_depolyment/model/keras_model.h5'  
new_model = keras.models.load_model(path)

# pass  tflite converter to flatbuffer
tflite_converter = tf.lite.TFLiteConverter.from_keras_model(new_model)
tflite_converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]  # 大小优化 
keras_tflite = tflite_converter.convert()

# write to file as byte
with open('./tf_model_save_and_depolyment/model/quantized_keras_tflite','wb') as f:
    f.write(keras_tflite)
